<?php

namespace App\Console\Commands;

use App\Repositories\OrderRespository;
use App\Repositories\UserRepository;
use App\UserMoneyLog;
use Carbon\Carbon;
use Illuminate\Console\Command;

class SettlementCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Commission:settlement';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '结算10天以前的佣金';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
       $user= new UserRepository();

       UserMoneyLog::where('created_at','<',Carbon::today()->addDays(-10))->where('status','!=',1)->chunk(10,function($data)use($user){
           foreach ($data as $v){
               $user->setellement($v->id);
               $this->info($v->id.'已结算');
           }

       });
    }
}
